import { ApiProperty } from '@nestjs/swagger';
import {
  IsString,
  IsOptional,
  MaxLength,
  IsDateString,
  IsNumber,
} from 'class-validator';
import { Type } from '@nestjs/class-transformer';
import { SongResponseDto } from '../song/song.dto';
// import { PaginationResponseDto } from '../song/song.dto';

// 创建专辑DTO
export class CreateAlbumDto {
  @ApiProperty({
    description: '专辑名称',
    example: '叶惠美',
    maxLength: 100,
  })
  @IsString()
  @MaxLength(100)
  title: string;

  @ApiProperty({
    description: '歌手ID',
    example: 1,
  })
  @IsNumber()
  artistId: number;

  @ApiProperty({
    description: '发行日期',
    example: '2003-07-31',
    required: false,
  })
  @IsOptional()
  @IsDateString()
  releaseDate?: string;

  @ApiProperty({
    description: '专辑封面URL',
    example: 'https://example.com/album-cover.jpg',
    required: false,
  })
  @IsOptional()
  @IsString()
  coverImageUrl?: string;

  @ApiProperty({
    description: '专辑描述',
    example: '周杰伦2003年发行的专辑',
    required: false,
    maxLength: 5000,
  })
  @IsOptional()
  @IsString()
  @MaxLength(5000)
  description?: string;
}

// 更新专辑DTO
export class UpdateAlbumDto {
  @ApiProperty({
    description: '专辑名称',
    example: '叶惠美',
    required: false,
    maxLength: 100,
  })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  title?: string;

  @ApiProperty({
    description: '歌手ID',
    example: 1,
    required: false,
  })
  @IsOptional()
  @IsNumber()
  artistId?: number;

  @ApiProperty({
    description: '发行日期',
    example: '2003-07-31',
    required: false,
  })
  @IsOptional()
  @IsDateString()
  releaseDate?: string;

  @ApiProperty({
    description: '专辑封面URL',
    example: 'https://example.com/album-cover.jpg',
    required: false,
  })
  @IsOptional()
  @IsString()
  coverImageUrl?: string;

  @ApiProperty({
    description: '专辑描述',
    example: '周杰伦2003年发行的专辑',
    required: false,
    maxLength: 5000,
  })
  @IsOptional()
  @IsString()
  @MaxLength(5000)
  description?: string;
}

// 专辑分页查询参数DTO
export class AlbumsPaginationQueryDto {
  @ApiProperty({ description: '页码', example: 1, required: false })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  page?: number = 1;

  @ApiProperty({ description: '每页数量', example: 10, required: false })
  @IsOptional()
  @Type(() => Number)
  @IsNumber()
  limit?: number = 10;

  @ApiProperty({
    description: '搜索关键词',
    example: '周杰伦',
    required: false,
  })
  @IsOptional()
  @IsString()
  searchTerm?: string;
}

// 专辑响应DTO
export class AlbumResponseDto {
  @ApiProperty({ description: '专辑ID' })
  id: number;

  @ApiProperty({ description: '专辑名称' })
  title: string;

  @ApiProperty({ description: '歌手信息' })
  artist: {
    id: number;
    name: string;
  };

  @ApiProperty({ description: '发行日期' })
  releaseDate?: Date;

  @ApiProperty({ description: '专辑封面URL' })
  coverImageUrl?: string;

  @ApiProperty({ description: '专辑描述' })
  description?: string;

  @ApiProperty({ description: '播放次数' })
  plays: number;

  @ApiProperty({ description: '专辑内的歌曲列表' })
  songs: SongResponseDto[];

  @ApiProperty({ description: '创建时间' })
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  updatedAt: Date;
}
